package com.muyu.vehicle.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vehicle.common.log.annotation.Log;
import com.vehicle.common.log.enums.BusinessType;
import com.vehicle.common.security.annotation.PreAuthorize;
import com.muyu.vehicle.domain.VehicleFaultLog;
import com.muyu.vehicle.service.IVehicleFaultLogService;
import com.vehicle.common.core.web.controller.BaseController;
import com.vehicle.common.core.web.domain.AjaxResult;
import com.vehicle.common.core.utils.poi.ExcelUtil;
import com.vehicle.common.core.web.page.TableDataInfo;

/**
 * 车辆故障报警记录Controller
 *
 * @author muyu
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/faultLog")
public class VehicleFaultLogController extends BaseController
{
    @Autowired
    private IVehicleFaultLogService vehicleFaultLogService;

    /**
     * 查询车辆故障报警记录列表
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleFaultLog vehicleFaultLog)
    {
        startPage();
        List<VehicleFaultLog> list = vehicleFaultLogService.selectVehicleFaultLogList(vehicleFaultLog);
        return getDataTable(list);
    }

    /**
     * 导出车辆故障报警记录列表
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:export")
    @Log(title = "车辆故障报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleFaultLog vehicleFaultLog) throws IOException
    {
        List<VehicleFaultLog> list = vehicleFaultLogService.selectVehicleFaultLogList(vehicleFaultLog);
        ExcelUtil<VehicleFaultLog> util = new ExcelUtil<VehicleFaultLog>(VehicleFaultLog.class);
        util.exportExcel(response, list, "车辆故障报警记录数据");
    }

    /**
     * 获取车辆故障报警记录详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(vehicleFaultLogService.selectVehicleFaultLogById(id));
    }

    /**
     * 新增车辆故障报警记录
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:add")
    @Log(title = "车辆故障报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleFaultLog vehicleFaultLog)
    {
        return toAjax(vehicleFaultLogService.insertVehicleFaultLog(vehicleFaultLog));
    }

    /**
     * 修改车辆故障报警记录
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:edit")
    @Log(title = "车辆故障报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleFaultLog vehicleFaultLog)
    {
        return toAjax(vehicleFaultLogService.updateVehicleFaultLog(vehicleFaultLog));
    }

    /**
     * 删除车辆故障报警记录
     */
    @PreAuthorize(hasPermi = "vehicle:faultLog:remove")
    @Log(title = "车辆故障报警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(vehicleFaultLogService.deleteVehicleFaultLogByIds(ids));
    }
}
